#ifndef __MP_NET_CONTEXT_H__
#define __MP_NET_CONTEXT_H__

#include "eventloop.h"

#include <sstream>
#include <random>
#include <string>
#include <iostream>
#include <queue>

#include <unistd.h>

#define member_of(node, type, member) \
    ((type *)((char *)(node) - (unsigned long)(&((type *)0)->member)))

struct NetSendBuffer {
    size_t      send_pos = 0;
    std::string buffer;
};

class NetContext {
public:
    NetContext();
    virtual ~NetContext();

    //public function
    std::string gen_uuid();
    void send_message(const std::string& message);

public:
    int sd = -1;

    ev::io rx_io;
    ev::io tx_io;

    std::string rx_buffer;
    std::deque<NetSendBuffer> tx_buffer_list;

    //client info
    std::string remote_host;
    int remote_port;

    //session id
    std::string session_id;
};

#endif